package cn.limc.ohoscharts.demo.slice;

import cn.limc.ohoscharts.demo.common.BaseAbility;
import cn.limc.ohoscharts.demo.ResourceTable;
import cn.limc.ohoscharts.axis.Axis;
import cn.limc.ohoscharts.entity.DateValueEntity;
import cn.limc.ohoscharts.entity.IStickEntity;
import cn.limc.ohoscharts.entity.LineEntity;
import cn.limc.ohoscharts.entity.ListChartData;
import cn.limc.ohoscharts.event.IZoomable;
import cn.limc.ohoscharts.view.MASlipStickChart;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;

import java.util.ArrayList;
import java.util.List;

public class MASlipStickChartAbility extends BaseAbility {
  MASlipStickChart maslipstickchart;

  @Override
  protected void onStart(Intent intent) {
    super.onStart(intent);
    setUIContent(ResourceTable.Layout_ability_maslip_stick_chart);
    initMASlipStickChart();
  }


//
//    @Override
//    public boolean onCreateOptionsMenu(Menu menu) {
//        // Inflate the menu; this adds items to the action bar if it is present.
//        getMenuInflater().inflate(R.menu.maslip_stick_chart, menu);
//        return true;
//    }

  private void initMASlipStickChart() {
    this.maslipstickchart = (MASlipStickChart) findComponentById(ResourceTable.Id_maslipstickchart);

    // 以下计算VOL
    List<LineEntity<DateValueEntity>> vlines = new ArrayList<LineEntity<DateValueEntity>>();

    // 计算5日均线
    LineEntity<DateValueEntity> VMA5 = new LineEntity<DateValueEntity>();
    VMA5.setTitle("MA5");
    VMA5.setLineColor(Color.WHITE.getValue());
    VMA5.setLineData(initVMA(5));
    vlines.add(VMA5);

    // 计算10日均线
    LineEntity<DateValueEntity> VMA10 = new LineEntity<DateValueEntity>();
    VMA10.setTitle("MA10");
    VMA10.setLineColor(Color.RED.getValue());
    VMA10.setLineData(initVMA(10));
    vlines.add(VMA10);

    // 计算25日均线
    LineEntity<DateValueEntity> VMA25 = new LineEntity<DateValueEntity>();
    VMA25.setTitle("MA25");
    VMA25.setLineColor(Color.GREEN.getValue());
    VMA25.setLineData(initVMA(25));
    vlines.add(VMA25);

    maslipstickchart.setAxisXColor(Color.LTGRAY.getValue());
    maslipstickchart.setAxisYColor(Color.LTGRAY.getValue());
    maslipstickchart.setLatitudeColor(Color.GRAY.getValue());
    maslipstickchart.setLongitudeColor(Color.GRAY.getValue());
    maslipstickchart.setBorderColor(Color.LTGRAY.getValue());
    maslipstickchart.setLongitudeFontColor(Color.WHITE.getValue());
    maslipstickchart.setLatitudeFontColor(Color.WHITE.getValue());

    // 最大纬线数
    maslipstickchart.setLatitudeNum(2);
    // 最大经线数
    maslipstickchart.setLongitudeNum(3);
    // 最大价格
    maslipstickchart.setMaxValue(600000);
    // 最小价格
    maslipstickchart.setMinValue(100);

    maslipstickchart.setDisplayFrom(10);

    maslipstickchart.setDisplayNumber(30);

    maslipstickchart.setMinDisplayNumber(5);

    maslipstickchart.setZoomBaseLine(IZoomable.ZOOM_BASE_LINE_CENTER);

    maslipstickchart.setDisplayLongitudeTitle(true);
    maslipstickchart.setDisplayLatitudeTitle(true);
    maslipstickchart.setDisplayLatitude(true);
    maslipstickchart.setDisplayLongitude(true);
    ShapeElement background = new ShapeElement();
    background.setRgbColor(new RgbColor(00, 00, 00));
    maslipstickchart.setBackground(background);


    maslipstickchart.setDataQuadrantPaddingTop(5);
    maslipstickchart.setDataQuadrantPaddingBottom(5);
    maslipstickchart.setDataQuadrantPaddingLeft(5);
    maslipstickchart.setDataQuadrantPaddingRight(5);
//      maslipstickchart.setAxisYTitleQuadrantWidth(50);
//      maslipstickchart.setAxisXTitleQuadrantHeight(20);
    maslipstickchart.setAxisXPosition(Axis.AXIS_X_POSITION_BOTTOM);
    maslipstickchart.setAxisYPosition(Axis.AXIS_Y_POSITION_RIGHT);

    // 为chart1增加均线
    maslipstickchart.setLineData(vlines);
    // 为chart1增加均线
    maslipstickchart.setStickData(new ListChartData<IStickEntity>(vol));
  }
}
